

Ext.define('ExtJs.controller.system.SystemControl',{
	extend: 'Ext.app.Controller',
	views: [
		//框架
		'system.System',
		'system.module.SystemTree',
		'system.module.SystemGrid',
		'system.module.UserGrid',
		'system.module.Systeminfo'
		
		
    ],
   
     stores:[
     //数据
    	'system.module.SystemTreeStore',
     	'system.module.SystemGridStore',
     	'system.module.UserGridStore'
//     	'system.module.UserAGridStore',
//     	'system.module.UserCGridStore',
     
   		
    ],
    models:[
    	'system.module.SystemModel',
    	'system.module.UserModel'
    ],
   
    refs: [
    	{
            ref: 'system',
            selector: 'system'
        },
        {
            ref: 'systemTree',
            selector: 'systemTree'
        },
         {
        	ref:'systemGrid',
        	selector:'systemGrid'
        },
        {
        	ref:'userGrid',
        	selector:'userGrid'
        },
       
        {
        	ref:'systemGridStore',
        	selector:'systemGridStore'
        },
        {
        	ref:'userGridStore',
        	selector:'userGridStore'
        }
   
    ],
    init: function () {
    	//this.getSystemTree().getStore().load();
    	
    	var govInfoControl = this;
        govInfoControl.control({
        	
        	'systemTree':{
        		itemclick:function(view, rec, item, index, e){
        			
        			
        			 //定义面板编号前缀
        			var moduleTabId = 'govInfoModuleGrid_'+rec.get('id');
        		
        			//获得tabpanel对象
        			var govinfo_frame_center = Ext.getCmp('system').getComponent('system_center');
        			//通过编号获得面板
        			var tab = govinfo_frame_center.getComponent(moduleTabId);
        			
        			if(!tab&&rec.get('text')=='供应商'){//管理员管理
        				tab = govinfo_frame_center.add({
        					xtype:'systemGrid',
        					title:rec.get('text'),
        					id:moduleTabId,
        					closable:true,
        					moduleId:rec.get('id')
        				});
        				tab.getStore().load();
        			}else if(!tab&&rec.get('text')=='管理员'){//管理员信息
        				tab = govinfo_frame_center.add({
        					xtype:'userGrid',
        					title:rec.get('text'),
        					id:moduleTabId,
        					closable:true,
        					moduleId:rec.get('id')
        				});
        				tab.getStore().load();
        			}else if(!tab&&rec.get('text')=='库管'){//库管信息
        				tab = govinfo_frame_center.add({
        					xtype:'userGrid',
        					title:rec.get('text'),
        					id:moduleTabId,
        					closable:true,
        					moduleId:rec.get('id')
        				});
        				tab.getStore().load();
        			}else if(!tab&&rec.get('text')=='员工'){//员工信息
        				tab = govinfo_frame_center.add({
        					xtype:'userGrid',
        					title:rec.get('text'),
        					id:moduleTabId,
        					closable:true,
        					moduleId:rec.get('id')
        				});
        				tab.getStore().load();
        			}else if(!tab&&rec.get('text')=='库房'){//系统信息
        				tab = govinfo_frame_center.add({
        					xtype:'systeminfo',
        					url: '../servlet/wareHouse.update',
        					title:rec.get('text'),
        					id:moduleTabId,
        					closable:true,
        					moduleId:rec.get('id')
        				});
        				 // 发送请求-form初期化
						MyExt.ajaxRequest({
							baseUrl: '',
							action: '../servlet/wareHouse.show',
							callback: function(jsonResult){
								tab.getForm().setValues(jsonResult);
								//var basicForm = editUserFormPanel.getForm();
								//basicForm.findField('user').setValue('admin');
								
							}
						});
        				
        			}
        			
        			//获得 store 对象
        			govinfo_frame_center.setActiveTab(tab);
        			
        		}
        	}
        });
    }
});